/*
 * @Author: ShawnPhang
 * @Date: 2024-05-11 14:42:15
 * @Description: 音频相关接口
 * @LastEditors: Lzg <https://m.palxp.cn>
 * @LastEditTime: 2024-05-11 11:40:47
 */
import fetch from '@/utils/axios'
import { IGetTempListData } from './home'

type TokenParam = {
    token: string
}
// 分类类型
export type TGetCatListData = {
    id: number
    name: string
    orders: number
    soft: number
    agent_id: number
}
export type TGetCatListResult = TCommResResult<TGetCatListData[]>
// 获取分类
export const getCatList = (params: TokenParam) =>  fetch<TGetCatListResult>('/api/sound/get_cat', params, 'post')

type TGetTimbreParam = {
    cat_id: number
}& Partial<TokenParam>

export type TGetTimbreListResult = {
    id: number
    user_id: number
    agent_id: number
    name: string
    logo: string
    status: number
    cfg_id?: number
    url?: string
    text?: string
    users?: number
    soft?: number
    cat_id?: number
    voice?: string
}

export type TGetTimbreResult = TCommResResult<TGetTimbreListResult[]>

// 获取分类下列表：
export const getTimbreList = (params: TGetTimbreParam) => fetch<TGetTimbreResult>('/api/sound/get_timbre_list', params, 'post')

export type TGetSoundParam = {
    // item: number
    // page: number
} & Partial<TokenParam>


export type TGetSoundItemData = {
    id: number
    user_id: number
    agent_id: number
    times: number
    title: string
    create_time: string
    timbre_id?: number
    url?: string
    text?: string
    soft?: number
    timbre_name?: string
    isPlay?: boolean
}

interface Response {
    list: TGetSoundItemData[]
    page_num: number
}


export type TGetSoundResult = TCommResResult<Response>

// 获取音频列表
export const getSoundList = (params: TGetSoundParam) => fetch<TGetSoundResult>('/api/sound/get_sound_list', params, 'post')


type GetSubmitSoundParam = {
    timbre_id: string | number
    text: string | number
    speech_rate: number
    pitch_rate: number
}& Partial<TokenParam>

export type TGetSubmitSoundItemData = {
    data?: string
}

export type TGetSubmitSoundResult = TCommResResult<TGetSubmitSoundItemData>
// 音频合成
export const getSubmitSound = (params: { pitch_rate: number; timbre_id: number | string | {} | undefined; speech_rate: number; text: string; token: string }) => fetch<TGetSubmitSoundResult>('/api/sound/submit_sound', params, 'post')
// 登录获取token
type GetTokenParam = {
    username: string
    password: string
}

export type TGetTokenData = {
    token: string
}

export type TGetTokenResult = TCommResResult<TGetTokenData>
// 获取token
export const getToken = (params: GetTokenParam) => fetch<TGetTokenResult>('/api/users/login', params, 'post')


// 删除音频
type DelSoundParam = {
    sound_id: number
}& Partial<TokenParam>

export type TDelSoundData = {
    data: any
}

export type TDelSoundResult = TCommResResult<TDelSoundData>
// 删除接口
export const getDelSound = (params: DelSoundParam) => fetch<TDelSoundResult>('/api/sound/del_sound', params, 'post')

// 上传

type FormData = {
    file_name: string
    token: string
    file: string
} & Partial<TokenParam>


export type TGetSubmitSoundItemData = {
    data?: string
}

export type TGetSubmitSoundResult = TCommResResult<TGetSubmitSoundItemData>

export const getSubmitsSound = (params: FormData) => fetch<TGetSubmitSoundResult>('/api/sound/submits_sound', params, 'post')

